package com.df.bpm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.df.bpm.dto.BusinessInformationDTO;
import com.df.bpm.entity.BusinessOutputs;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface BusinessOutputsMapper extends BaseMapper<BusinessOutputs> {

    /**
     * 按输出物查询目标业务
     */
    @Select("SELECT bif.*  \n" +
            "FROM businessOverview.businessOutputs bop\n" +
            "LEFT JOIN businessOverview.businessInformationDTO bif ON bif.businessInformationIndex=bop.businessInformationIndex \n" +
            "where bop.businessEntityIndex=#{entityId} ")
    List<BusinessInformationDTO> getBusinessesDto(Integer entityId);


    /**
     * 按输出物查询目标业务
     */
    @Select("SELECT bif.* \n" +
            "FROM businessOverview.businessOutputs bop \n" +
            "LEFT JOIN businessOverview.businessInformationDTO bif ON bif.businessInformationIndex=bop.businessInformationIndex \n" +
            "where bop.businessEntityIndex=#{entityId} and bif.businessInformationIndex not in (\n" +
            "\tSELECT bl.businessInformationIndex as sonIds \n" +
            "\tFROM businessOverview.businessOutputs bop \n" +
            "\tLEFT JOIN businessOverview.businessInformationDTO bif ON bif.businessInformationIndex=bop.businessInformationIndex \n" +
            "\tLEFT JOIN businessOverview.businessLocations bl ON bl.superior=bif.businessInformationIndex \n" +
            "\twhere bop.businessEntityIndex=#{entityId} and bl.businessInformationIndex is not null \n" +
            ")\n")
    List<BusinessInformationDTO> getBusinessesDtoUnRepeat(Integer entityId);

}